package com.xuce.nzshopadminweb.controller;

import com.xuce.nzshopadminweb.client.AdminClient;
import com.xuce.pojo.TUser;
import com.xuce.dto.ResultEnum;
import com.xuce.dto.ResultResponse;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * @author 徐策
 * @date 2020/3/15 15:39
 */
@Controller
@Scope("prototype")
public class AdminWebController {
    @Resource
    AdminClient adminClient;

    /**
     * 登录方法 返回ResultResponse
     */
    @PostMapping("/admin_login")
    @ResponseBody
    public ResultResponse<TUser> adminLogin(TUser tUser){
        TUser loginAdmin = adminClient.AdminLogin(tUser);
        if(loginAdmin!=null){
            if(loginAdmin.getFlag().equals("0")){
                return  ResultResponse.success(tUser, ResultEnum.UNACTIVE);
            }else {
                return ResultResponse.success(tUser,ResultEnum.SUCCESS);
            }
        }else {
            return ResultResponse.fail(ResultEnum.FAIL,tUser);
        }
    }
}
